package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.dto.TagListDto;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.domain.vo.TagVo;
import com.sangeng.service.TagService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/tag")
@RequiredArgsConstructor
public class TagController {
    private final TagService tagService;

    @GetMapping("/listAllTag")
    public ResponseResult<List<TagVo>> listAllTag(){
        return tagService.listAllTag();
    }
    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDto tagListDto) {
        return tagService.pageTagList(pageNum, pageSize, tagListDto);
    }

    //删除标签
    @DeleteMapping("/{idList}")
    public ResponseResult<String> deleteTag(@PathVariable List<Long> idList) {
        return tagService.deleteTagById(idList);
    }

    //新增标签
    @PostMapping
    public ResponseResult<String> addTag(@RequestBody @Validated TagVo tag) {
        return tagService.addTag(tag);
    }

    //修改标签
    @GetMapping("/{id}")
    public ResponseResult<TagVo> getCategory(@PathVariable Long id) {
        return tagService.getTagById(id);
    }

    @PutMapping
    public ResponseResult<String> updateTagInfo(@RequestBody TagVo tagVo) {

        return tagService.updateTagInfo(tagVo);
    }
}
